package cn.terminus.biz.customer.contractsellbystagesinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractsellbystagesinfo.dto.*;
import cn.terminus.data.customer.contractsellbystagesinfo.dao.ContractSellByStagesInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (ContractSellByStagesInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:16:43
 */
@Component
public class ContractSellByStagesInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellByStagesInfoDao contractSellByStagesInfoDao;

    public Integer add(ContractSellByStagesInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellByStagesInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellByStagesInfoResultDto> gets(ContractSellByStagesInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellByStagesInfoResultDto> query(ContractSellByStagesInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellByStagesInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellByStagesInfoResultDto> page(ContractSellByStagesInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellByStagesInfoResultDto> result = (Page<ContractSellByStagesInfoResultDto>) contractSellByStagesInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellByStagesInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer insertBatch(List<ContractSellByStagesInfoNewDto> byStagesInfoNewDtos) throws DataAccessException {
        try {
            return contractSellByStagesInfoDao.insertBatch(byStagesInfoNewDtos);
        } catch (Exception e) {
            logger.error("ContractSellByStagesInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
